package com.chixing.day19_thread;

public class ABC {
    public static void main(String[] args) {

        Thread a = new Base(0,"A");
        Thread b = new Base(1,"B");
        Thread c = new Base(2,"C");
        a.start();
        b.start();
        c.start();
    }
}


class Base extends Thread{
    //共享锁
    private static Object lock = new Object();

    //定义记录打印次数
    private static int count = 0;

    //一个记录当前打印的是什么
    private int flag;
    private String value;

    public Base(int flag, String value) {
        this.flag = flag;
        this.value = value;
    }

    @Override
    public void run() {
        for (int i=0;i<10;i++){
            synchronized (lock){
                while (count % 3 != flag){
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println(value);
                count++;
                lock.notifyAll();
            }
        }
    }
}